package com.xx.springboot.DataStructure.LeetCode.LinkedList;


import com.xx.springboot.DataStructure.Stack.LinkedListStack;

import javax.sound.midi.Soundbank;
import java.util.Stack;

/**
 * Created by xiaoxiunique on 2018-8-22.   1 - > 2 - > 3
 */
public class reverseList {

    public ListNode reverseList(ListNode head) {
        if(head.next == null)
            return head;
        ListNode dummy = head;
        ListNode cur = reverseList(head.next);
        cur.next = dummy;
        dummy.next = null;
        return cur;
    }



    public ListNode reverseList1(ListNode head) {
        if(head == null)
            return head;

        Stack<Integer> stack = new Stack<>();
        ListNode cur = head;
        while (cur != null){
            stack.push(cur.val);
            cur = cur.next;
        }

        ListNode dummyHead = new ListNode(-1);
        ListNode curDummyHead = dummyHead;
        while (!stack.isEmpty()) {
            curDummyHead.next = new ListNode(stack.pop());
            curDummyHead = curDummyHead.next;
        }
        return dummyHead.next;
    }

    public static void main(String[] args) {
        int[] nums = {1, 2};
        ListNode listNode = new ListNode(nums);
        (new reverseList()).reverseList(listNode);
        System.out.println(listNode);
    }
}
